//
//  XKPagingView.h
//  BaiYing_Thinker
//
//  Created by 鹏 朱 on 15/10/29.
//  Copyright (c) 2015年 XKJH. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef enum {
    ATPagingViewVertical,
    ATPagingViewHorizontal
} ATPagingViewDirection;

@protocol ATPagingViewDelegate;

@interface XKPagingView : UIView {

    NSInteger _firstLoadedPageIndex;
    NSInteger _lastLoadedPageIndex;
    NSMutableSet *_recycledPages;
    NSMutableSet *_visiblePages;

    BOOL _rotationInProgress;
}

@property(nonatomic, assign) ATPagingViewDirection direction; //default is ATPagingViewHorizontal;

@property(nonatomic, weak) id<ATPagingViewDelegate> delegate;

@property(nonatomic, assign) CGFloat gapBetweenPages;  // default is 20

@property(nonatomic, assign) NSInteger pagesToPreload;

@property(nonatomic, assign) NSInteger pageCount;

@property(nonatomic, assign) NSInteger currentPageIndex;
@property(nonatomic, assign, readonly) NSInteger previousPageIndex;
@property(nonatomic, assign, readonly) NSInteger firstVisiblePageIndex;
@property(nonatomic, assign, readonly) NSInteger lastVisiblePageIndex;

@property(nonatomic, assign, readonly) NSInteger firstLoadedPageIndex;
@property(nonatomic, assign, readonly) NSInteger lastLoadedPageIndex;
@property(nonatomic, strong)  UIScrollView *scrollView;

@property(nonatomic, assign) BOOL scrollViewIsMoving;
@property(nonatomic, assign) BOOL recyclingEnabled;
@property(nonatomic, assign)BOOL openAnimator;
@property(nonatomic, strong) NSArray* ds;

- (void)setCurrentPageIndex:(NSInteger)newPageIndex openAnimator:(BOOL)openAnimator;

- (void)reloadData;  
- (void)reloadDataAtIndex:(NSInteger)index;

- (UIView *)viewForPageAtIndex:(NSUInteger)index;

- (UIView *)dequeueReusablePage;

- (void)willAnimateRotation;

- (void)didRotate;

- (id)initVerticalWithFrame:(CGRect)frame;

@end


@protocol ATPagingViewDelegate <NSObject>

@required

- (NSInteger)numberOfPagesInPagingView:(XKPagingView *)pagingView;

- (UIView *)viewForPageInPagingView:(XKPagingView *)pagingView atIndex:(NSInteger)index;

@optional

- (void)currentPageDidChangeInPagingView:(XKPagingView *)pagingView;
- (void)pagesDidChangeInPagingView:(XKPagingView *)pagingView;
- (void)pagingViewWillBeginMoving:(XKPagingView *)pagingView;
- (void)pagingViewDidEndMoving:(XKPagingView *)pagingView;

- (NSMutableArray *)tableViewDataSource:(XKPagingView *)pagingView atIndex:(NSInteger)index;

@end

@interface ATPagingViewController : UIViewController <ATPagingViewDelegate> {
    XKPagingView *_pagingView;
}

@property(nonatomic, strong) XKPagingView *pagingView;

@end
